package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.service.MarketAdminHistoryService;
import com.cskaoyan.market.service.impl.MarketAdminHistoryServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("admin/history")
public class AdminHistoryController {
    @Autowired
    MarketAdminHistoryService service;

    @GetMapping("list")
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // 获取请求
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        String userId = req.getParameter("userId");
        String keyword = req.getParameter("keyword");

        System.out.println("req.keyword = " + keyword);

        String sort = req.getParameter("sort");
        String order = req.getParameter("order");

        List<MarketSearchHistory> marketSearchHistories = service.list(page,limit,userId,keyword,sort,order);

        Object o = ResponseUtil.okList(marketSearchHistories);
        String s = JacksonUtil.writeValueAsString(o);

        resp.getWriter().println(s);
    }
}
